if lib and not lib.GetTime then


function lib:GetTime()
	return os.clock()
end


function lib:IsDelay(time, delay)
	local now = self:GetTime()
	if not time or time >= 0 and (time + int(delay) / 1000.0 <= now) then
		return now
	end
end


function lib:getTradeDate()
	local d = getTradeDate()
	if type(d) == "table" then
		if not d.year or d.year < 2000 then
			d = os.sysdate()
		end
		d.hour = 0
		d.min = 0
		d.sec = 0
	end
	return d
end


function lib:isticktime(t)
	--if string.match(t, "^%d%d%d%d%d%d%.%d%d%d%d%d%d") then
	if string.match(t, "^%d%d%d%d%d%d%.%d%d%d") then
		return true
	end
end


function lib:ticktime(d)
	d = d or os.sysdate()
	if type(d) == "table" then
		--return string.format("%02d%02d%02d.%03d%03d",
		return string.format("%02d%02d%02d.%03d",
			d.hour or 0, d.min or 0, d.sec or 0,
			d.ms or 0--, d.mcs or 0
		)
	elseif d >= 0 and d < 86400 then
		return lib:ticktime({
			--mcs = int(d % 1 * 1000000 % 1000),
			ms = int(d % 1 * 1000),
			sec = int(d % 60),
			min = int(d / 60 % 60),
			hour = int(d / 3600 % 24)
		})
	end
	return lib:ticktime(os.date("*t", int(d)))
end


function lib:tickdate(t, d)
	t = t or os.sysdate()
	if type(t) == "string" then
		if not self:isticktime(t) then return end
		d = d or os.sysdate()
		--d.mcs = int(string.sub(t, 11, 13))
		d.mcs = nil
		d.ms = int(string.sub(t, 8, 10))
		d.sec = int(string.sub(t, 5, 6))
		d.min = int(string.sub(t, 3, 4))
		d.hour = int(string.sub(t, 1, 2))
		return d
	elseif type(t) == "table" then
		return t
	elseif t >= 0 and t < 86400 then
		d = d or os.sysdate()
		--d.mcs = int(t % 1 * 1000000 % 1000)
		d.mcs = nil
		d.ms = int(t % 1 * 1000)
		d.sec = int(t % 60)
		d.min = int(t / 60 % 60)
		d.hour = int(t / 3600 % 24)
		return d
	end
	return os.date("*t", int(t))
end


function lib:tickseconds(t)
	t = t or os.sysdate()
	if type(t) == "string" then
		if not self:isticktime(t) then return end
		return (int(string.sub(t, 1, 2)) * 60 + int(string.sub(t, 3, 4))) * 60 + int(string.sub(t, 5, 6))
	elseif type(t) == "table" then
		return (int(t.hour) * 60 + int(t.min)) * 60 + int(t.sec)
	end
	return int(t) % 86400
end


end -- of file
